<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>add</title>
		<link href="<?php echo base_url();?>public/css/bootstrap.min.css" rel="stylesheet">
		<link href="<?php echo base_url();?>public/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css">
	  	<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>public/style/style.css">

		<script charset="utf-8" src="<?php echo base_url();?>public/kindeditor/kindeditor-all-min.js"></script>
		<script charset="utf-8" src="<?php echo base_url();?>public/kindeditor/lang/zh-CN.js"></script>
		<script>
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create(["#content"]);
				})
				
		</script>
		<script type="text/javascript" src="<?php echo base_url();?>public/js/jquery.js"></script>
		<script type="text/javascript" src="<?php echo base_url();?>public/js/jquery.upload.js"></script>
</head>
<body>
	<?php include("nav.php");?>
	<div class="container">
		<div class="row">
			<div class="col-md-9 col-md-offset-1">
			<div class="page-header">
			  <h1><?php echo $title;?><small>文章</small></h1>
			</div>	
				<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
					<div class="form-group">
						<label class="col-sm-2 control-label"><span class="error">*</span>分类</label>
						<div class="col-sm-3">
							<select class="form-control" name="catalog_id">
								<option value="">请选择一个分类</option>
								<?php foreach ($navs as  $nav) { ?>
								<option <?php echo  set_select('catalog_id', $nav->id, $nav->id == $article->catalog_id); ?> value="<?php echo $nav->id;?>"><?php echo $nav->name;?></option>
								<?php } ?>	
							</select>
							<?php echo form_error('catalog_id'); ?>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label"><span class="error">*</span>标题</label>
						<div class="col-sm-10">
							<input type="text"　 class="form-control" name="title" value="<?php echo set_value('title',$article->title);?>"  />
							<?php echo form_error('title'); ?>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label"><span class="error">*</span>描述</label>
						<div class="col-sm-10">
							<textarea class="form-control" name="desc" rows="5"><?php echo set_value('desc',$article->desc);?></textarea>
							<?php echo form_error('desc'); ?>
						</div>
					</div>
					<div class="form-group" >
						<label class="col-sm-2 control-label"><span class="error">*</span>内容</label>
						<div class="col-sm-10">
							<textarea class="form-control"  name="content" id="content"><?php echo set_value('content',$article->content);?></textarea>
							<?php echo form_error('content'); ?>
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label"><span class="error">*</span>图片</label>
						<div class="col-sm-5">
							<input type="text" id="img" class="form-control"  name="img" value="<?php echo set_value('img',$article->img)?>" />
							<a id="upload" href="#">上传文件</a>
							<?php echo form_error('img'); ?>
						</div>
						<div class="col-sm-5" id="preview">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label"></label>
						<div class="col-sm-10">
							<a href="<?php echo site_url("admin/article/add");?>"><button type="submit" class="btn btn-success">提交</button></a>
							<a  class="btn btn-success " role="button" href="<?php echo site_url("admin/article/index");?>">返回</a>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
	$("#upload").click(function(K){
		$.upload({
	        url: '<?php echo site_url("admin/util/upload")?>', 
	        fileName: 'file', 
	        dataType: 'text',
	        onSend: function() {
	            return true;
	        },
	        onComplate: function(data) {
	        	if(data.indexOf("upload") >=0){
	        		$("#img").val(data);
	        		$("#preview").html('<img style="height:80px;" src="<?php echo base_url()."public/"?>'+data+'" />')
	        	}else{
 					alert(data);
	        	}
	        	
	        }
		});
	})
	
</script>

